import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import path from 'path'

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  css: {
    loaderOptions: {
      less: {
        // 全局注入 Less 文件
        additionalData: `
          @import "@/styles/global.less";
        `,
      },
    },
  },
  server: {
    proxy: {
      '/api': {
        target: 'http://10.8.57.172:7011', // 后端服务的地址
        changeOrigin: true, // 允许跨域
        // rewrite: (path) => path.replace(/^\/api/, ''), // 重写路径
      },
    },
  },
})
